<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('发通知')"/>
    <th:block th:include="include :: jasny-bootstrap-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-notice-add">
        <!--主题-->
        <div class="form-group col-sm-12">
            <label class="col-sm-3 control-label is-required">主题 <span>(必填)</span></label>
            <div class="col-sm-8">
                <input name="noticeTheme" class="form-control" type="text" th:field="*{notice.noticeTheme}"
                       placeholder="请输入" required>
            </div>
        </div>
        <!--内容
        <div class="form-group col-sm-12">
            <label class="col-sm-3 control-label is-required">内容 <span>(必填)</span></label>
            <div class="col-sm-8">
                <textarea name="noticeContent" class="form-control" rows="4" type="text"
                          th:field="*{notice.noticeContent}" placeholder="请输入" required></textarea>
            </div>
        </div>-->
        <!--附件-->
        <div class="form-group">
            <label class="col-sm-3 control-label">附件 <span>(最大50M)</span></label>
            <div class="col-sm-8 fileinput" th:classappend="${file.fileRoute} ? 'fileinput-exists' : 'fileinput-new'" data-provides="fileinput" style="margin-bottom: 0;">
                <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 800px; height: 40px; margin-right: 10px;">
                    <img th:if="${file.fileRoute}" th:text="${file.fileName}">
                </div>
                <span class="btn btn-white btn-file">
                    <span class="fileinput-new">选择附件</span>
                    <span class="fileinput-exists">更改</span>
                    <input name="file" type="hidden" th:value="${file.fileRoute}">
                    <input id="williamYe" type="file">
                </span>
                <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
            </div>
        </div>
        <!--署名-->
        <div class="form-group col-sm-12">
            <label class="col-sm-3 control-label">署名</label>
            <div class="col-sm-8">
                <input name="noticeSignature" class="form-control" th:field="*{notice.noticeSignature}"
                       placeholder="请输入" type="text">
            </div>
        </div>
        <!--接收对象-->
        <div class="form-group col-sm-12">
            <label class="col-sm-3 control-label is-required">接收对象 <span>(必填)</span></label>
            <div class="col-sm-8">
                <input id="addresseeName" name="addresseeName" th:value="${addresseeName}" type="hidden">
                <textarea id="realName" class="col-sm-10" rows="3" type="text" style="margin-right: 20px;"
                          th:value="${realNames}" placeholder="请选择接收对象" readonly></textarea>
                <span class="btn btn-info" style="margin-top: 10px">
                    <span href="javascript:void(0)" onclick="checkTree()">
                        <i class="fa fa-paper-plane"></i>选择接收对象
                    </span>
                </span>
            </div>
        </div>
        <!--类型-->
        <div class="form-group col-sm-12">
            <label class="col-sm-3 control-label is-required">通知类型</label>
            <div class="col-sm-8">
                <div class="radio-box" style="height: 34px;" th:each="dict : ${@dict.getType('sys_notice_type')}">
                    <input type="radio" th:id="${'type_' + dict.id}" name="noticeType" th:value="${dict.itemValue}" th:checked="${dict.isDefault == 'Y' ? true : false}">
                    <label th:for="${'type_' + dict.id}" th:text="${dict.itemText}"></label>
                </div>
            </div>
        </div>
        <!--<div class="form-group col-sm-12">
            <label class="col-sm-3 control-label">是否发送短信</label>
            <div class="col-sm-8">

                <select name="noticeMessage" class="form-control m-b"
                        th:with="type=${@dict.getType('sys_notice_message')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.itemText}" th:value="${dict.itemValue}"
                            th:field="*{notice.noticeMessage}"></option>
                </select>
            </div>
        </div>-->
        <!--短信-->
        <div class="form-group col-sm-12">
            <label class="col-sm-3 control-label is-required">是否发送短信</label>
            <div class="col-sm-8">
                <div class="radio-box" style="height: 34px;" th:each="dict : ${@dict.getType('sys_notice_message')}">
                    <input type="radio" th:id="${'message_' + dict.id}" name="noticeMessage" th:value="${dict.itemValue}" th:checked="${dict.isDefault == 'Y' ? true : false}">
                    <label th:for="${'message_' + dict.id}" th:text="${dict.itemText}"></label>
                </div>
            </div>
        </div>
    </form>
    <!--发送取消按钮-->
    <div class="form-group col-sm-12" style="margin-top: 100px">
        <div style="text-align: center">
            <a class="btn btn-success" href="javascript:void(0)" onclick="sendThis()"><i
                    class="fa fa-paper-plane"></i> 发送</a>
            <a class="btn btn-danger" href="javascript:void(0)" onclick="returnThis()"><i
                    class="fa fa-close"></i> 取消</a>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: jasny-bootstrap-js"/>
<script type="text/javascript">
    var prefix = ctx + "education/notice";

    $('#williamYe').on('change.bs.fileinput ', function (e) {
        // 处理自己的业务
        if (this.files[0]) {
            const formData = new FormData();
            formData.append('file', this.files[0]);
            $.operate.fileUpload(formData, $('input[name="file"]'));
        } else {
            $('input[name="file"]').val("");
        }
    });

    $("#form-notice-add").validate({
        focusCleanup: true
    });

    function sendThis() {
        if ($.validate.form()) {
            save(prefix + "/add", $('#form-notice-add').serialize(), function (res) {
                if (res.success) {
                    $.modal.close();
                }
            });
        }
    }

    function returnThis() {
        if ($.validate.form()) {
            save(prefix + "/toDraft", $('#form-notice-add').serialize(), function (res) {
                if (res.success) {
                    $.modal.close();
                }
            });
        }
    }

    function save(url, data, callback) {
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            beforeSend: function (request) {
                request.setRequestHeader("X-Access-Token", storage.get("token"));
            },
            success: function (result) {
                $.operate.saveSuccess(result);
            }
        };
        $.ajax(config)
    }

    function checkTree() {
        var options = {
            title: "选择接收对象",
            width: 800 ,
            height: ($(window).height() - 50) ,
            url: prefix + "/tree",
            skin: 'layui-layer-gray',
            btn:['确定', '关闭'],
            yes: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function(index) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }

    function setName(addresseeName,realName){
        $('#addresseeName').val(addresseeName);
        $('#realName').val(realName);
    }

</script>
</body>
</html>
